/****************************************************
*	OSMF Edge Media Player version 1.2.0
* 
*	Author: Emanuele Manco
* 	E-Mail: hello@flashedge.net
*	Web: http://activeden.net/user/flashedge
*  
*****************************************************/

package net.flashedge.display 
{
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	public class Objects extends Sprite
	{
		public var ring:Ring = new Ring();				// buffering animated sprite
		public var shader:Sprite = new Sprite();
		
		public var mainMask:Sprite = new Sprite();
		public var playerMask:Sprite = new Sprite();
		public var spectrumMask:Sprite = new Sprite();
		
		public var playBtn:PlayButton = new PlayButton();
		public var pauseBtn:PauseButton = new PauseButton();
		public var forwardBtn:ForwardButton = new ForwardButton();
		public var backBtn:BackButton = new BackButton();
		
		public var shuffleBtn:ShuffleButton = new ShuffleButton();
		public var playmodeBtn:PlaymodeButton = new PlaymodeButton();
		public var shareBtn:ShareButton = new ShareButton();
		public var volumeBtn:VolumeButton = new VolumeButton();
		
		public var hdBtn:HDBtn = new HDBtn();
		public var fsBtn:FullscreenButton = new FullscreenButton();
		
		public var header:Sprite = new Sprite();
		public var toolbar:ToolBar = new ToolBar();
		
		public var bg:Sprite = new Sprite();
		
		public var headerBg:Sprite = new Sprite();
		public var toolbarTooltips:Sprite = new Sprite();
		
		public var bigPlayBtn:BigPlayBtn = new BigPlayBtn();
		public var replayBtn:ReplayBtn = new ReplayBtn();
		public var bigButton:Sprite = new Sprite();
		public var bigButtonBg:Sprite = new Sprite();
		
		public var titleField:TextField;
		public var titleFormat:TextFormat;
		public var titleFont:primaryFont = new primaryFont();
		
		public function Objects() 
		{
			shader.name = "shader";
			ring.name = "ring";
			fsBtn.name = "fsbtn";
		}
		
		public function createRing(w:Number, h:Number):void {
			addChild(ring);
			ring.x = w * .5;
			ring.y = h * .5;
		}
		
		public function createBg(w:Number, h:Number):void {
			addChild(bg);
			bg.graphics.beginFill(0x000000, 1);
			bg.graphics.drawRect(0, 0, w, h);
			bg.graphics.endFill();
		}
		public function createShader(w:Number, h:Number):void {
			
			trace ("Creating shader: "+w + h);
			addChild(shader);
			
			shader.graphics.beginFill(0x000000, 0.5);
			shader.graphics.drawRect(0, 0, w, h);
			shader.graphics.endFill();

		}
		
		public function createMainMask(w:Number, h:Number):void {
			addChild(mainMask);
			
			mainMask.graphics.beginFill(0x00000, 1);
			mainMask.graphics.drawRect(0, 0, w, h);
			mainMask.graphics.endFill();
		}
		
		public function createPlayerMask(w:Number, h:Number):void {
			addChild(playerMask);
			
			playerMask.graphics.beginFill(0x00000, 1);
			playerMask.graphics.drawRect(0, 0, w, h);
			playerMask.graphics.endFill();
		}
		
		public function createSpectrumMask(w:Number, h:Number):void {
			addChild(spectrumMask);
			
			spectrumMask.graphics.beginFill(0x00000, 1);
			spectrumMask.graphics.drawRect(0, 0, w, h);
			spectrumMask.graphics.endFill();
		}
		
		
		public function createHeaderBg(w:Number, h:Number):void {
			header.addChild(headerBg);
			header.addChild(toolbar);
			toolbar.addChild(toolbarTooltips);
			toolbar.y = 10;
			
			var matrix:Matrix;
			var colors:Array;
			var alphas:Array;
			var ratios:Array;
			  
			matrix = new Matrix();
			colors = [0x000000,0x000000];
			alphas = [1,0.5];
			ratios = [0,255];
			
			matrix.createGradientBox(w, h, 90*Math.PI/180);
			headerBg.graphics.lineStyle(1, 0xE2E2E2, 0.2, true);
			headerBg.graphics.beginGradientFill(GradientType.LINEAR,colors,alphas,ratios,matrix);
			headerBg.graphics.drawRect(-1,-1,w+2,h+2);
			headerBg.graphics.endFill();
			
			header.y = - header.height;
			
			for (var i = 0; i < toolbar.numChildren -1 ; i++) {
				toolbar.getChildAt(i).alpha = .6;
			}
		}
		
		public function createBigButton(w:Number = 80, h:Number = 80, r:Number = 20):void {
			bigButton.alpha = 0;
			bigButton.visible = false;
			bigButton.buttonMode = true;
			
			bigButton.addChild(bigButtonBg);
			bigButton.addChild(bigPlayBtn);
			bigButton.addChild(replayBtn);
			
			bigButtonBg.graphics.lineStyle(1, 0xE2E2E2, 0.5, true);
			bigButtonBg.graphics.beginFill(0x000000, 0.7);
			bigButtonBg.graphics.drawRoundRect( -w*.5, -h*.5, w, h, r, r);
			bigButtonBg.graphics.endFill();
			bigButtonBg.alpha = 0.7;
			
			bigPlayBtn.width = bigPlayBtn.height = w - 26;
			replayBtn.width = replayBtn.height = w - 26;
			
			replayBtn.visible = false;
			
			var bigFilters = new GlowFilter(0x000000, 0.2, 8, 8, 2, 1, false);
			bigButtonBg.filters = [bigFilters]; 
		}
		
		public function refreshBigButton(w:Number = 80, h:Number = 80, r:Number = 20):void {
			
			bigButtonBg.graphics.clear();
			bigButtonBg.graphics.lineStyle(1, 0xE2E2E2, 0.5, true);
			bigButtonBg.graphics.beginFill(0x000000, 0.6);
			bigButtonBg.graphics.drawRoundRect( -w*.5, -h*.5, w, h, r, r);
			bigButtonBg.graphics.endFill();
			
			bigPlayBtn.width = bigPlayBtn.height = h - 26;
			replayBtn.width = replayBtn.height = h - 26;
		}
		
		public function createTitle(titleContent:String,  titleColor:uint, size, offsetX, offsetY):void {
			
			titleField = new TextField();
			titleField.autoSize = TextFieldAutoSize.LEFT;
			titleField.background = false;
			titleField.embedFonts = true;
			titleField.border = false;
			titleField.selectable = false;
			titleField.antiAliasType = AntiAliasType.ADVANCED;
			
			titleFormat = new TextFormat();
			titleFormat.font = titleFont.fontName;
			titleFormat.color = titleColor;
			titleFormat.size = size;
			
			titleField.defaultTextFormat = titleFormat;
				
			titleField.htmlText = titleContent;
			titleField.x = offsetX;
			titleField.y = offsetY;
			
			header.addChild(titleField);
		}
		
		public function clear():void {
			playerMask.graphics.clear();
			removeChild(playerMask);
			
			mainMask.graphics.clear();
			removeChild(mainMask);
			
			spectrumMask.graphics.clear();
			removeChild(spectrumMask);
			
			bg.graphics.clear();
			removeChild(bg);
			
			header.graphics.clear();
			removeChild(header);
			
			headerBg.graphics.clear();
			removeChild(headerBg);
			
			bigButtonBg.graphics.clear();
			removeChild(bigButtonBg);
			
			bigButton.graphics.clear();
			removeChild(bigButton);
			}
	}

}